package com.campus.admin.controller;


import com.campus.common.core.domain.AjaxResult;
import com.campus.pojos.domain.dto.UserDto;
import com.campus.pojos.domain.dto.UserQueryDto;
import com.campus.pojos.domain.vo.UserVo;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import oshi.jna.platform.mac.SystemB;

import java.util.List;

@RestController(value = "adminUserController")
@RequestMapping("/system/admin/user")
@Slf4j
public class UserController {
   @Autowired
    private UserService userService;
    @PostMapping("/list")
    public AjaxResult getUserList(@RequestBody UserQueryDto queryDto){
        return userService.queryList(queryDto);
    }

    @PutMapping("/status")
    public AjaxResult status(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "status", required = true) Integer status
    ){
        userService.status(userId,status);
        return AjaxResult.success();
    }

    /**
     * 编辑用户信息
     * @param userDto
     * @return
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody UserDto userDto){
        userService.edit(userDto);
        return AjaxResult.success();
    }

    /**
     * 根据id获取用户信息
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public AjaxResult getById(@PathVariable Long id){
        return AjaxResult.success("success",userService.getByUserId(id));
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id){
        userService.removeById(id);
        return AjaxResult.success();
    }

    /**
     * 根据ids删除用户
     * @return
     */
    @DeleteMapping("/deleteBatch")
    public AjaxResult deleteById(@RequestParam(value = "ids",required = false) List<Integer> ids){
        userService.removeByIds(ids);
        return AjaxResult.success();
    }


}
